#coding:utf-8
from apscheduler.schedulers.blocking import BlockingScheduler
from datetime import datetime
from threading import Timer  
import time,types
def tick(params):
    print('Tick! The time is: %s' % datetime.now())
    print params

def Spider_sched(func,timestramps,**kwargs):
    try:
        scheduler = BlockingScheduler(daemonic = False)
        if type(timestramps)==types.ListType and timestramps is not None:
            for stramp in timestramps:
                times=time.localtime(stramp)
                datetimes=datetime(times[0],times[1],times[2],times[3],times[4],times[5])
                scheduler.add_job(func,'date',run_date=datetimes,args=[kwargs])   
        elif type(timestramps==types.IntType):
            times=time.localtime(timestramps)
            datetimes=datetime(times[0],times[1],times[2],times[3],times[4],times[5])
            scheduler.add_job(func,'date',run_date=datetimes,args=[kwargs],id="my_job")   
        
        scheduler.start()
        
        
    except Exception,e:
        print e
        
def spider_timer(func,timer_interval):
    t=Timer(timer_interval,func)  
    t.start() 
    
 
if __name__=="__main__":
    Spider_sched(tick,int(time.time()),**dict({"id":1,"name":"xiong"}))
    print "ss"
    exit(0)
    #spider_timer(tick, 1)